import { createRouter, createWebHistory } from 'vue-router'
import LoginPage from '../views/LoginPage.vue'
import WelcomePage from '../views/WelcomePage.vue'
import HomePage from '../views/HomePage.vue'
const routes = [
  { path: '/', redirect: 'login' },
  { path: '/login', component: LoginPage },
  {
    path: '/home',
    component: HomePage,
    redirect: '/welcome',
    children: [
      { path: '/welcome', component: WelcomePage },

    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 添加导航守卫处理未知错误
router.beforeEach((to, from, next) => {
  try {
    next()
  } catch (error) {
    console.error('路由导航错误:', error)
    next({ path: '/login', query: { error: 'unknown' } })
  }
})

export default router
